<template>
    <div>
    <h2 class="larns">有学籍老用户转购</h2>
     <div class="buttoncon">
        <Button type="primary"  @click="Workshops" >累计购买研习社</Button>
    <Button type="success" @click="Business" >累计购买19商</Button>
    </div>
        <Table border :loading="loading" :columns="columns1" :data="data1"></Table>
        <br>
  <!-- <Switch v-model="loading"></Switch> -->
    </div>
</template>
<script>
    export default {
        data () {
            return {
                loading: true,
                            columns1: [
                    {
                        title: '用户sku属性',
                        key: 'sku',
                        align: 'center',
           
                    },
                    {
                        title: '4月1日用户基数',
                        key: 'user',
                        align: 'center',
                
                    },
                      {
                        title: '累计购买研习社',
                        key: 'Workshops',
                        align: 'center',
                          SKUindex:['yxs','sxy19','sxy','cxy','sxy-sxy19','yxs-sxy','yxs-cxy','sxy-cxy','sxy-cxy','sxy-sxy19-cxy','yxs-sxy-cxy'],
                         render: (h, params) => { 
                            var elem="";
                             // console.log(params) 
                             if (params.index==params.column.SKUindex.length) 
                                   {
                                     var elem ='p'
                                   } else{
                                    var elem ='a'
                                   }                           
                              return    h(elem, {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                            console.log(params.column)
                                              console.log(params.column.SKUindex[params.index])
                                              var Sku=params.column.SKUindex[params.index]
                                                  if (typeof  Sku == "undefined") 
                                                {
                                                  return false
                                                 // window.location.href="information.html?sku=" +nls+"&sku_z=date_sxy19"
                                                }
                                                  this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: Sku,
                                                            sku_z:"date_yxs"
                                                          }
                                                        })
                                              // window.location.href="information.html?sku="+Sku+"&sku_z=date_yxs"
                                            
                                      
                                        }
                                    }
                                },  params.row.Workshops)
                            
                           
                        }
             
                    },
                               {
                        title: '累计购买19商',
                        key: 'Business',
                        align: 'center',
                      SKUindex:['yxs','sxy19','sxy','cxy','sxy-sxy19','yxs-sxy','yxs-cxy','sxy-cxy','sxy-cxy','sxy-sxy19-cxy','yxs-sxy-cxy'],
                        // tabs:""
                            render: 
                             (h, params) => { 
                              var elem="";
                             // console.log(params) 
                             if (params.index==params.column.SKUindex.length) 
                                   {
                                     var elem ='p'
                                   } else{
                                    var elem ='a'
                                   }                                        
                              return   h(elem, {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                             console.log(params.column)
                                              console.log(params.column.SKUindex[params.index])
                                              var Sku=params.column.SKUindex[params.index]
                                              console.log( typeof  Sku)
                                              if (typeof  Sku == "undefined") 
                                                {
                                                  return false
                                                 // window.location.href="information.html?sku=" +nls+"&sku_z=date_sxy19"
                                                }else{
                                                    this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: Sku,
                                                            sku_z:"date_sxy19"
                                                          }
                                                        })
                                                  // window.location.href="information.html?sku="+Sku+"&sku_z=date_sxy19"
                                                }
                                                
                                              // window.location.href="information.html?sku="+Sku+"&sku_z=date_sxy19"
                                        }
                                    }
                                },  params.row.Business)
                          
                           
                        }
                    },
                     {
                        title: '累积转购',
                        key: 'transfer',
                        align: 'center'
                    },
                    {
                        title: '累计转购率',
                        key: 'LV',
                        align: 'center'
                    }
                ],
                data1: [
                    {
                        sku: '研习社',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                   {
                        sku: '19商',
                        user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                     {
                        sku: '18商',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                     {
                        sku: '创新院',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                     {
                        sku: '18商+19商',
                         user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                     {
                        sku: '研习社+18商',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                    {
                        sku: '研习社+创新院',
                        user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                    {
                        sku: '18商+创新院',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                    {
                        sku: '19商+创新院',
                      user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                    {
                        sku: '18商+19商+创新院',
                        user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                    {
                        sku: '研习社+18商+创新院',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    },
                        {
                        sku: '合计',
                       user: 0,
                        Workshops: 0,
                       Business:  0,
                      transfer: 0,
                        LV: 0
                    }
                ]
            }
        },
    created(){
            var that =this;

        // console.log(this.Util.URL())
this.axios({
      method: 'get',
      url: this.Util.URL()+'/v1/buy-stat/stat-all'
    })
    .then(function (response) {
        console.log(response)
      console.log(response.data.data)
      var Data =response.data.data[0]
      // console.log(that.data1)
          for (var i = 0; i < response.data.data.length; i++) {
            // Things[i]
            console.log(response.data.data[i])
          }




      // 用户基数
      that.data1[0].user=response.data.data[0].yxscount
      that.data1[1].user=response.data.data[0].sxy19count
      that.data1[2].user=response.data.data[0].sxy18count
      that.data1[3].user=response.data.data[0].cxycount
      that.data1[4].user=response.data.data[0].sxy18Andsxy19
      that.data1[5].user=response.data.data[0].yxsAndsxy18
      that.data1[6].user=response.data.data[0].yxsAndcxy
       that.data1[7].user=response.data.data[0].sxy18Andcxy
       that.data1[8].user=response.data.data[0].sxy19Andcxy
       that.data1[9].user=response.data.data[0].sxy18Andsxy19Andcxy
       that.data1[10].user=response.data.data[0].yxsAndsxy18Andcxy
       that.data1[11].user=parseInt(  Data.yxscount )+parseInt(  Data.sxy19count )+parseInt(  Data.sxy18count )+parseInt(  Data.cxycount )+parseInt(  Data.sxy18Andsxy19 )+parseInt(  Data.yxsAndsxy18)+parseInt(  Data.yxsAndcxy )+parseInt(  Data.sxy18Andcxy )+parseInt(  Data.sxy19Andcxy )+parseInt(  Data.sxy18Andsxy19Andcxy )+parseInt(  Data.yxsAndsxy18Andcxy )
      // 累计购买研习社
       that.data1[0].Workshops=0
      that.data1[1].Workshops=response.data.data[0].sxy19Zyxs
      that.data1[2].Workshops=response.data.data[0].sxy18Zyxs
      that.data1[3].Workshops=response.data.data[0].cxyZyxs
      that.data1[4].Workshops=response.data.data[0].sxy18Andsxy19Zyxs
      that.data1[5].Workshops=0
      that.data1[6].Workshops=0
       that.data1[7].Workshops=response.data.data[0].sxy18AndcxyZyxs
       that.data1[8].Workshops=response.data.data[0].sxy19AndcxyZyxs
       that.data1[9].Workshops=response.data.data[0].sxy18Andsxy19AndcxyZyxs
       that.data1[10].Workshops=response.data.data[0].yxsAndsxy18AndcxyZyxs
       // console.log(0+parseInt(  Data.sxy19Zyxs )+parseInt(  Data.sxy18Zyxs ))
        that.data1[11].Workshops=0+parseInt(  Data.sxy19Zyxs )+parseInt(  Data.sxy18Zyxs )+parseInt( Data.cxyZyxs)+parseInt(  Data.sxy18Andsxy19Zyxs )+0+0+parseInt(  Data.sxy18AndcxyZyxs )+parseInt(  Data.sxy19AndcxyZyxs )+parseInt(  Data.sxy18Andsxy19AndcxyZyxs )+parseInt(  Data.yxsAndsxy18AndcxyZyxs )
    // 累计购买19商学院
        that.data1[0].Business=response.data.data[0].yxsZsxy19
        // console.log(response.data.data[0].yxsZsxy19)
        // console.log(that.data1[0].Business)
      that.data1[1].Business=0
      that.data1[2].Business=response.data.data[0].sxy18Zsxy19
      that.data1[3].Business=response.data.data[0].cxyZsxy19
      that.data1[4].Business=0
      that.data1[5].Business=response.data.data[0].yxsAndsxy18Zsxy19
      that.data1[6].Business=response.data.data[0].yxsAndcxyZsxy19
       that.data1[7].Business=response.data.data[0].sxy18AndcxyZsxy19
       that.data1[8].Business=0
       that.data1[9].Business=0
       that.data1[10].Business=response.data.data[0].yxsAndsxy18AndcxyZsxy19
        that.data1[11].Business=parseInt(  Data.yxsZsxy19 )+0+parseInt(  Data.sxy18Zsxy19 )+parseInt( Data.cxyZsxy19)+0 +parseInt(  Data.yxsAndsxy18Zsxy19)+parseInt(  Data.yxsAndcxyZsxy19 )+parseInt(  Data.sxy18AndcxyZsxy19 )+0+0+parseInt(  Data.yxsAndsxy18AndcxyZsxy19)
        // 累积转购和累计转购率
       for (var i = 0; i < that.data1.length; i++) {
           that.data1[i].transfer =parseInt(that.data1[i].Workshops)+parseInt(that.data1[i].Business)
           that.data1[i].LV =(parseInt( that.data1[i].transfer )/parseInt(that.data1[i].user)*100).toFixed(2)+"%"
       }
      
        
    })
    .catch(function (error) {
      console.log(error)
    }).finally(() => this.loading = false)
    },
         methods: {
            Workshops() {
               // window.location.href="pastdata.html?Skus="+"yxs"
                this.$router.push({
          path: '/Catalog/Pastdata',
          query: {
            Skus: "yxs"
          }
        })
            },
            Business(){
        this.$router.push({
          path: '/Catalog/Business',
          query: {
            Skus: "sxy"
          }
        })
            }
 }
    }
</script>
<style scoped>
    .larns{
        text-align: center;
    }
        .buttoncon{
        margin:16px 0;
        display: flex;
        justify-content: flex-end;
     }
     .buttoncon button{
        margin-right: 10px;
     }
</style>
